<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>标题</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui/css/layui.css">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<form class="layui-form searchForm">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label" style="width: 100px;">发送人：</label>
            <div class="layui-input-inline">
                <input type="text" name="sender" id="sender" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label" style="width: 100px;">接收人：</label>
            <div class="layui-input-inline">
                <input type="text" name="receiver" id="receiver" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-input-inline">
                <button class="layui-btn layui-btn-normal" id="queryBut">搜索</button>
            </div>
        </div>
    </div>
</form>
<table class="layui-hide" id="dataList" lay-filter="dataList"></table>

<script type="text/html" id="toolbarOrg">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="del">批量删除</button>
    </div>
</script>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    <a class="layui-btn layui-btn-sm layui-btn-xs" lay-event="edit">邮件详情</a>
</script>

<script type="text/javascript" src="/lib/layui/layui.js"></script>
<script src="/static/js/main.js"></script>
<script>
    var configureCom = {};
    layui.use(['jquery', 'configureCom', 'configure', 'sessionFun', 'table', 'matchDict'], function () {
        var $ = layui.jquery;
        var configure = layui.configure;
        var table = layui.table;
        var sessionFun = layui.sessionFun;
        configureCom = layui.configureCom;
        var cols = [[
            {type: 'checkbox', fixed: 'left',width:'40'},
            {field: 'subject', title: '邮件主题',width:'200'},
            {field: 'sender', title: '发送人',width:'180'},
            {field: 'receiver', title: '接收人',width:'180'},
            {field: 'sendDate', title: '发送时间',width:'180'},
            {field: 'type', title: '邮件类型',width:'100',
                templet: function (d) {
                    var text = '';
                    if (d.type == 0) {
                        text = '系统邮件';
                    } else if(d.type == 1){
                        text = '用户邮件';
                    }else{
                        text = '系统邮件';
                    }
                    return text;
                }},
            {field: 'sendResult',width:'100', title: '邮件状态',
                templet: function (d) {
                    var text = '';
                    if (d.sendResult == 0) {
                        text = '发送成功';
                    } else if(d.sendResult == 2){
                        text = '发送失败';
                    }else{
                        text = '发送中';
                    }
                    return text;
                }},
            {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 150}
        ]];
        configureCom.tableRender(configure.MAIL_LOG_HTTP_LIST, {}, cols, 'dataList', 10, 'full-200', 'toolbarOrg');
        //头工具栏事件
        table.on('toolbar(dataList)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            sessionFun.remove(configure.SESSION_LIST_DATA);
            switch (obj.event) {
                case 'del':
                    var data = checkStatus.data;
                    if (!data.length) {
                        top.layer.alert('请您至少选择一条数据后再提交！');
                        return false;
                    }
                    top.layer.confirm('您真的要删除选中的数据吗？', function (index, layero) {
                        top.layer.close(index);
                        var ids = '';
                        $(data).each(function (index, item) {
                            if (!index) {
                                ids = item.id;
                            } else {
                                ids += ',' + item.id;
                            }
                        });
                        deleteFun(ids);
                    });
                    break;
            }
        });
        //每行操作
        table.on('tool(dataList)', function (obj) {
            var data = obj.data;
            sessionFun.set(configure.SESSION_LIST_DATA, data);
            if (obj.event === 'del') {//查看详情
                deleteFun(data.id);
            }
            if (obj.event === 'edit') {//查看详情
                editItem("邮件日志详情",data.id);
            }
        });

        function deleteFun(ids) {
            top.layer.confirm('您真的要删除这条数据吗？', function () {
                configureCom.postDataAjax(configure.MAIL_LOG_HTTP_DELETE, {ids: ids}).then(function (res) {
                    if (res.code == 0) {
                        top.layer.msg('删除成功！');
                        configureCom.tableReload(true);
                    } else {
                        top.layer.alert('删除失败！');
                    }
                });
            });
        }

        //查看邮件详情
        function editItem(title, url) {
            top.layer.open({
                type: 2,
                title: title,
                area: configureCom.Psize1,
                content: configureCom.nocache(configure.MAIL_LOG_HTML_INFO),
                btn: ['关闭'],
                yes: function (index) {
                    top.layer.close(index);
                }
            });
        }
    });

</script>
</body>
</html>